//========================================================================
// This file was generated using the MyGeneration tool in combination
// with the Gentle.NET Business Entity template, $Rev: 1104 $
//========================================================================
using System;
using System.Collections;
using Gentle.Common;
using Gentle.Framework;

namespace GrewalCRM.Entities
{
	/// <summary>
	/// Instances of this class represent the properties and methods of a row in the table <b>CustomersMaster</b>.
	/// </summary>
	[TableName("CustomersMaster", CacheStrategy.Temporary)]
	public class CustomersMaster : BaseEntitiesGrewalCRM
	{
		#region Members
		private bool isChanged;
		private int customerID;
		private string customeName;
		private string address;
		private string zipCode;
		private string phoneNo;
		private string mobileNo;
		private int lastModifiedUser;
		private DateTime lastModifiedDateTime;
		#endregion
			
		#region Constructors
		/// <summary>
		/// Create a new instance using the default constructor
		/// </summary>
		public CustomersMaster()
		{
			isChanged = true;
		}

		/// <summary> 
		/// Create a new object using the minimum required information (all not-null fields except 
		/// auto-generated primary keys). 
		/// </summary> 
		public CustomersMaster(string customeName, string address, string zipCode, int lastModifiedUser, DateTime lastModifiedDateTime)
		{
			isChanged = true;
			customerID = 0;
			this.customeName = customeName;
			this.address = address;
			this.zipCode = zipCode;
			this.lastModifiedUser = lastModifiedUser;
			this.lastModifiedDateTime = lastModifiedDateTime;
		}

		/// <summary> 
		/// Create a new object by specifying all fields (except the auto-generated primary key field). 
		/// </summary> 
		public CustomersMaster(string customeName, string address, string zipCode, string phoneNo, string mobileNo, int lastModifiedUser, DateTime lastModifiedDateTime)
		{
			isChanged = true;
			this.customeName = customeName;
			this.address = address;
			this.zipCode = zipCode;
			this.phoneNo = phoneNo;
			this.mobileNo = mobileNo;
			this.lastModifiedUser = lastModifiedUser;
			this.lastModifiedDateTime = lastModifiedDateTime;
		}
			
		/// <summary> 
		/// Create an object from an existing row of data. This will be used by Gentle to 
		/// construct objects from retrieved rows. 
		/// </summary> 
		public CustomersMaster(int customerID, string customeName, string address, string zipCode, string phoneNo, string mobileNo, int lastModifiedUser, DateTime lastModifiedDateTime)
		{
			this.customerID = customerID;
			this.customeName = customeName;
			this.address = address;
			this.zipCode = zipCode;
			this.phoneNo = phoneNo;
			this.mobileNo = mobileNo;
			this.lastModifiedUser = lastModifiedUser;
			this.lastModifiedDateTime = lastModifiedDateTime;
		}
		#endregion

		#region Public Properties
		/// <summary>
		/// Indicates whether the entity is changed and requires saving or not.
		/// </summary>
		public bool IsChanged
		{
			get { return isChanged; }
		}

		/// <summary>
		/// Property relating to database column CustomerID
		/// </summary>
		[TableColumn("CustomerID", NotNull=true), PrimaryKey(AutoGenerated=true)]
		public int CustomerID
		{
			get { return customerID; }
			set { isChanged |= customerID != value; customerID = value; }
		}

		/// <summary>
		/// Property relating to database column CustomeName
		/// </summary>
		[TableColumn("CustomeName", NotNull=true)]
		public string CustomeName
		{
			get { return customeName.TrimEnd(); }
			set { isChanged |= customeName != value; customeName = value; }
		}

		/// <summary>
		/// Property relating to database column Address
		/// </summary>
		[TableColumn("Address", NotNull=true)]
		public string Address
		{
			get { return address.TrimEnd(); }
			set { isChanged |= address != value; address = value; }
		}

		/// <summary>
		/// Property relating to database column ZipCode
		/// </summary>
		[TableColumn("ZipCode", NotNull=true)]
		public string ZipCode
		{
			get { return zipCode.TrimEnd(); }
			set { isChanged |= zipCode != value; zipCode = value; }
		}

		/// <summary>
		/// Property relating to database column PhoneNo
		/// </summary>
		[TableColumn("PhoneNo", NullValue="")]
		public string PhoneNo
		{
			get { return phoneNo != null ? phoneNo.TrimEnd() : string.Empty; }
			set { isChanged |= phoneNo != value; phoneNo = value; }
		}

		/// <summary>
		/// Property relating to database column MobileNo
		/// </summary>
		[TableColumn("MobileNo", NullValue="")]
		public string MobileNo
		{
			get { return mobileNo != null ? mobileNo.TrimEnd() : string.Empty; }
			set { isChanged |= mobileNo != value; mobileNo = value; }
		}

		/// <summary>
		/// Property relating to database column LastModifiedUser
		/// </summary>
		[TableColumn("LastModifiedUser", NotNull=true)]
		public int LastModifiedUser
		{
			get { return lastModifiedUser; }
			set { isChanged |= lastModifiedUser != value; lastModifiedUser = value; }
		}

		/// <summary>
		/// Property relating to database column LastModifiedDateTime
		/// </summary>
		[TableColumn("LastModifiedDateTime", NotNull=true)]
		public DateTime LastModifiedDateTime
		{
			get { return lastModifiedDateTime; }
			set { isChanged |= lastModifiedDateTime != value; lastModifiedDateTime = value; }
		}
		#endregion

		#region Storage and Retrieval
	
		/// <summary>
		/// Static method to retrieve all instances that are stored in the database in one call
		/// </summary>
		public static IList ListAll()
		{
			return Broker.RetrieveList(typeof(CustomersMaster));
		}

		/// <summary>
		/// Retrieves an entity given it's id.
		/// </summary>
		public static CustomersMaster Retrieve(int id)
		{
			Key key = new Key(typeof(CustomersMaster), true, "CustomerID", id);
			return Broker.RetrieveInstance(typeof(CustomersMaster), key) as CustomersMaster;
		}
		
		/// <summary>
		/// Retrieves an entity given it's id, using Gentle.Framework.Key class.
		/// This allows retrieval based on multi-column keys.
		/// </summary>
		public static CustomersMaster Retrieve(Key key)
		{
			return Broker.RetrieveInstance(typeof(CustomersMaster), key) as CustomersMaster;
		}
		
		/// <summary>
		/// Persists the entity if it was never persisted or was changed.
		/// </summary>
		public override void Persist()
		{
			if (IsChanged || !IsPersisted)
			{
				base.Persist();
				isChanged = false;
			}
		}

		#endregion

	}
}
